package com.example.homework3;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
{
    private Button button;
    private Button button2;
    private Button button3;
    private Button button4;
    private Button button5;
    private Button button6;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button=findViewById(R.id.button);
        button.setOnClickListener(this::onOldButtonClicked);

        button2=findViewById(R.id.button2);
        button2.setOnClickListener(this::onSimpleButtonClicked);

        button3=findViewById(R.id.button3);
        button3.setOnClickListener(this::onChoiceButtonClicked);

        button4=findViewById(R.id.button4);
        button4.setOnClickListener(this::Radiodialogbox);

        button5=findViewById(R.id.button5);
        button5.setOnClickListener(this::Multiplechoicedialogbox);

        button=findViewById(R.id.button6);
        button.setOnClickListener(this::CustomDialog);


    }
//旧版对话框
    public void onOldButtonClicked(View view)
    {
        AlertDialog dialog;
        dialog=new AlertDialog.Builder(this).setTitle("旧版对话框")
                .setMessage("这是旧版对话框，使用简单\n但是不支持屏幕翻转")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(),"你点击了确定",Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(),"你点击了取消",Toast.LENGTH_SHORT).show();
                    }
                })
                .create();
         dialog.show();
    }
//新版对话框
    public void onSimpleButtonClicked(View view)
    {
        SimpleDialogFragment dialog=new SimpleDialogFragment();
        dialog.show(getSupportFragmentManager(),"simple");
    }
//选择对话框
    public void onChoiceButtonClicked(View view)
    {
        ChoiceDialogFragment dialog=new ChoiceDialogFragment();
        dialog.SetLister(new ChoiceDialogFragment.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"你选择了："+gender,Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }
//单选对话框
   public void Radiodialogbox(View view)
    {
        Radiodialogbox dialog=new Radiodialogbox();
        dialog.SetLister(new Radiodialogbox.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"你选择了："+gender,Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }
//多选对话框
    public void Multiplechoicedialogbox(View view)
    {
        Multiplechoicedialogbox dialog=new Multiplechoicedialogbox();
        dialog.SetLister(new Multiplechoicedialogbox.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"你选择了："+gender,Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }
//自定义对话框
    public void CustomDialog(View view)
    {
        CustomDialog dialog=new CustomDialog();
        dialog.SetLister(new CustomDialog.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }
}